import ajax from './ajax'

const _processDownload = function(res, filename) {
  let link = document.createElement('a');
  link.href = window.URL.createObjectURL(res.data);
  link.download = filename;
  link.click();
}

export default {
   
    downloadReviews(days, onComplete) {
        ajax({
          url:'/douban/reviews/download?days=' + days,
          method:'POST',
          responseType:'blob'
        }).then(res=>{
          _processDownload(res, 'Douban-Review('+days+'days-rank)-' + new Date().getTime() + '.xlsx');
          onComplete();
        }).catch(onComplete);
      },

  loadReviews(days, sort, onSuccess) {
    ajax.get('/douban/reviews?limit=500&offset=0&days=' + days + '&sort=' + sort)
        .then(onSuccess); 
  }




};